<?php

namespace Trois\Init\Inits;

use App\ExceptionHandler;
use EasySwoole\Component\Di;
use EasySwoole\Component\Singleton;
use EasySwoole\EasySwoole\Core;
use EasySwoole\EasySwoole\SysConst;
use Trois\Design\Observer\IObserver;

class ErrorInit implements IObserver
{
    use Singleton;
    
    public function update()
    {

        if (Core::getInstance()->runMode() === 'dev') {
            // 开发者自定义设置 错误级别
            Di::getInstance()->set(SysConst::ERROR_REPORT_LEVEL, E_ALL);
        }

        //线上环境使用自定义错误处理
        Di::getInstance()->set(SysConst::HTTP_EXCEPTION_HANDLER, [ExceptionHandler::class, 'handle']);

    }
}